package edu.scut.course_management.handler;
import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
import org.springframework.stereotype.Component;

import edu.scut.course_management.result.JsonResult;
import edu.scut.course_management.result.JsonResultFactory;
import edu.scut.course_management.util.ResponseWritingUtil;

/**
 * 登出处理器 登出处理逻辑，返回前端 json 数据，提示“登出成功”
 */
@Component
public class LogoutHandler implements LogoutSuccessHandler {
    @Override
    public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
        JsonResult result = JsonResultFactory.getInstance().buildSuccessResult("登出成功");
        ResponseWritingUtil.writeJsonResultToResponse(response, result);
    }
}